﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunnyFunction
{
    public class Poker_FiveNiu
    {
        public static void Start(int pCount)
        {
            int[] SArr = new int[pCount];

            for (int i = 0; i < 100; i++)
            {
                Console.Write(".");
                Pokers pokers = Pokers.Init();
                pokers.Shuffle();

                int z = 0;
                for (int n = 0; n < pCount; n++)
                {
                    var pList = pokers.SendCount(5);
                    if (n == 0)
                    {
                        z = GetNum(pList);
                    }
                    else
                    {
                        var x = GetNum(pList);

                        if (x <= z)
                        {
                            var m = getMon(z);
                            SArr[n] -= m;
                            SArr[0] += m;
                        }
                        else
                        {
                            var m = getMon(x);
                            SArr[n] += m;
                            SArr[0] -= m;
                        }
                    }
                }
            }

            for (int i = 0; i < pCount; i++)
            {
                Console.WriteLine("i => " + SArr[i]);
            }
            Console.ReadLine();
        }

        private static int getMon(int z)
        {
            if (z >= 9)
                return 30;
            else if (z > 7)
                return 20;
            return 10;
        }

        private static int GetNum(List<Poker> pList)
        {
            List<int> list = new List<int>();
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    for (int k = 0; k < 5; k++)
                    {
                        if (i != j && i != k && j != k)
                        {
                            var fCount = getPNum(pList[i])+getPNum( pList[j])+getPNum( pList[k]);
                            if(fCount%10==0)
                            {
                                int count = 0;
                                for (int n = 0; n < 5; n++)
                                {
                                    if (n != i && n != j && n != k)
                                        count += getPNum(pList[n]);
                                }
                                count = count % 10;
                                if (count == 0)
                                    count = 10;

                                list.Add(count);
                            }
                        }
                    }
                }
            }
            if (list.Count > 0)
                return list.Max();

            return 0;
        }

        private static int getPNum(Poker p)
        {
            try
            {
                return int.Parse(p.num);
            }
            catch (Exception)
            {
                if (p.num == "A")
                    return 1;

                return 10;
            }
        }
    }
}
